package com.shkco.xbjcc.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shkco.exception.GlobalExceptionCode;
import com.shkco.result.JSONResult;
import com.shkco.utils.AssertUtil;
import com.shkco.xbjcc.domain.MessageSms;
import com.shkco.xbjcc.domain.Shielding;
import com.shkco.xbjcc.domain.User;
import com.shkco.xbjcc.dto.ShieldingDto;
import com.shkco.xbjcc.feign.UserService;
import com.shkco.xbjcc.mapper.MessageSmsMapper;
import com.shkco.xbjcc.service.IMessageSmsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.shkco.xbjcc.service.IShieldingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whale
 * @since 2022-09-24
 */
@Service
public class MessageSmsServiceImpl extends ServiceImpl<MessageSmsMapper, MessageSms> implements IMessageSmsService {

    @Autowired
    private IShieldingService shieldingService;

    @Autowired
    private UserService userService;

    @Autowired
    private MessageSmsMapper messageSmsMapper;

    @Override
    public void shielding(ShieldingDto shieldingDto) {
        Long userId = shieldingDto.getUserId();
        User user = userService.findById(userId);
        Shielding shield = shieldingService.findByPhone(user.getPhone());
        AssertUtil.isNull(shield, GlobalExceptionCode.USER_SHIELDING);
        Shielding shielding = new Shielding();
        shielding.setCause(shieldingDto.getCause());
        shielding.setPhone(user.getPhone());
        shielding.setIp(null);
        shielding.setUsername(user.getNickName());
        shieldingService.insert(shielding);
    }
}
